package com.ag.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ag.bean.TbExpert;

/**
 * A data access object (DAO) providing persistence and search support for
 * TbExpert entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.ag.bean.TbExpert
 * @author MyEclipse Persistence Tools
 */

public class TbExpertDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(TbExpertDAO.class);
	// property constants
	public static final String EXP_NAME = "expName";
	public static final String EXP_SEX = "expSex";
	public static final String EXP_IMG = "expImg";
	public static final String EXP_UNIT = "expUnit";
	public static final String EXP_EDUTCATION = "expEdutcation";
	public static final String EXP_DEREE = "expDeree";
	public static final String EXP_TITLE = "expTitle";
	public static final String EXT_PROFESSION = "extProfession";
	public static final String EXP_POST = "expPost";
	public static final String EXP_SCHOOL = "expSchool";
	public static final String EXP_RUSUME = "expRusume";
	public static final String EXP_FAX = "expFax";
	public static final String EXP_TEL = "expTel";
	public static final String EXP_MOBILE = "expMobile";
	public static final String A = "a";
	public static final String B = "b";
	public static final String C = "c";

	protected void initDao() {
		// do nothing
	}

	public void save(TbExpert transientInstance) {
		log.debug("saving TbExpert instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TbExpert persistentInstance) {
		log.debug("deleting TbExpert instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TbExpert findById(java.lang.String id) {
		log.debug("getting TbExpert instance with id: " + id);
		try {
			TbExpert instance = (TbExpert) getHibernateTemplate().get(
					"com.ag.bean.TbExpert", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<TbExpert> findByExample(TbExpert instance) {
		log.debug("finding TbExpert instance by example");
		try {
			List<TbExpert> results = (List<TbExpert>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TbExpert instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TbExpert as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<TbExpert> findByExpName(Object expName) {
		return findByProperty(EXP_NAME, expName);
	}

	public List<TbExpert> findByExpSex(Object expSex) {
		return findByProperty(EXP_SEX, expSex);
	}

	public List<TbExpert> findByExpImg(Object expImg) {
		return findByProperty(EXP_IMG, expImg);
	}

	public List<TbExpert> findByExpUnit(Object expUnit) {
		return findByProperty(EXP_UNIT, expUnit);
	}

	public List<TbExpert> findByExpEdutcation(Object expEdutcation) {
		return findByProperty(EXP_EDUTCATION, expEdutcation);
	}

	public List<TbExpert> findByExpDeree(Object expDeree) {
		return findByProperty(EXP_DEREE, expDeree);
	}

	public List<TbExpert> findByExpTitle(Object expTitle) {
		return findByProperty(EXP_TITLE, expTitle);
	}

	public List<TbExpert> findByExtProfession(Object extProfession) {
		return findByProperty(EXT_PROFESSION, extProfession);
	}

	public List<TbExpert> findByExpPost(Object expPost) {
		return findByProperty(EXP_POST, expPost);
	}

	public List<TbExpert> findByExpSchool(Object expSchool) {
		return findByProperty(EXP_SCHOOL, expSchool);
	}

	public List<TbExpert> findByExpRusume(Object expRusume) {
		return findByProperty(EXP_RUSUME, expRusume);
	}

	public List<TbExpert> findByExpFax(Object expFax) {
		return findByProperty(EXP_FAX, expFax);
	}

	public List<TbExpert> findByExpTel(Object expTel) {
		return findByProperty(EXP_TEL, expTel);
	}

	public List<TbExpert> findByExpMobile(Object expMobile) {
		return findByProperty(EXP_MOBILE, expMobile);
	}

	public List<TbExpert> findByA(Object a) {
		return findByProperty(A, a);
	}

	public List<TbExpert> findByB(Object b) {
		return findByProperty(B, b);
	}

	public List<TbExpert> findByC(Object c) {
		return findByProperty(C, c);
	}

	public List findAll() {
		log.debug("finding all TbExpert instances");
		try {
			String queryString = "from TbExpert";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TbExpert merge(TbExpert detachedInstance) {
		log.debug("merging TbExpert instance");
		try {
			TbExpert result = (TbExpert) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TbExpert instance) {
		log.debug("attaching dirty TbExpert instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TbExpert instance) {
		log.debug("attaching clean TbExpert instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TbExpertDAO getFromApplicationContext(ApplicationContext ctx) {
		return (TbExpertDAO) ctx.getBean("TbExpertDAO");
	}
}